// 用户留言表

module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const Message = app.model.define('message', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    content: { type: STRING(1000), allowNull: false }, // 留言内容
    nickname: { type: STRING, allowNull: false },
    user_name: { type: STRING, allowNull: true }, // 登录之后才有用户名
    email: { type: STRING, allowNull: false },
    user_id: { type: INTEGER, allowNull: true }, // 用户id
    created_at: { type: DATE, allowNull: false, defaultValue: new Date() }, // 发布时间
    admin_id: { type: INTEGER }, // 管理员id
  });
  Message.associate = function() {
    app.model.Message.hasMany(app.model.Reply, {
      foreignKey: 'comment_id',
      sourceKey: 'id',
      // as: 'hotel',
    });
  };
  return Message;
};
